package com.itwh.project.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

import static springfox.documentation.service.ApiInfo.DEFAULT_CONTACT;

/**
 * @Author 翁煌
 * @Date2020/7/5 000517:09
 * @Description:
 * @Version1.0
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    //配置swagger的Docket的bean实例
    @Bean
    public Docket docket(Environment environment){

        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true)  //配置是否启用swagger
                .select()// 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("com.itwh.project.controller"))
                .build();//工厂模式，创造什么东西
    }

    public ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("翁煌", "https://www.baidu.com/", "1325635198@qq.com");

        return new ApiInfo(
                "实验室可做项目api文档",
                "Api Documentation",
                "1.0",
                "https://www.baidu.com/",
                DEFAULT_CONTACT,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());

    }

}

